// EG4ParaManager.h -- an interface to ROOT for filling the generate
// sim data in a tree, and storing it in a root file
// Created: Oct. 11, 2024 by Asia SUN
// Last modified: Oct. 11, 2024 by Asia SUN

#include <iostream>
#include "EG4ParaManager.h"

using std::string;
using YAML::LoadFile;

EG4ParaManager *EG4ParaManager::fInstance = nullptr;

EG4ParaManager::EG4ParaManager() : fCtrlYaml(""){}

EG4ParaManager::~EG4ParaManager(){}

void EG4ParaManager::ReadParameters(const string &ctrl){
  if("" == ctrl){
      Node exp = LoadFile("../g4/config/exp.yaml");
      const string rootdir = "../g4/config/" + exp["exp"].as<string>() + "/";
      fDetPosConfig = LoadFile((rootdir + "detPos.yaml").data());
  } // end if
  else{
    fCtrlYaml = "../g4/config/b9/ctrl" + ctrl + ".yaml";
    fCtrlConfig = LoadFile(fCtrlYaml);
    const string rootdir = "../g4/config/" + fCtrlConfig["exp"].as<string>() + "/";
    fDetPosConfig = LoadFile(rootdir + "detPos.yaml");
  } // end else
} // end member function ReadParameters

EG4ParaManager *EG4ParaManager::Instance(){
  if(!fInstance) fInstance = new EG4ParaManager;
  return fInstance;
} // end member function Instance
